package com.sofly.controller.group3;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sofly.entity.DataGrid;
import com.sofly.entity.InStockInfo;
import com.sofly.service.group3.IInStockInfoService;

/**
 * 入库记录控制类
* <p>Title:InStockInfoController </p>
* <p>Description: </p>
* <p>Company: </p> 
* @author ChengShiMin
* @date 下午12:07:53
 */
@Controller
public class InStockInfoController {
	
	 @Autowired
	 private DataGrid dataGrid;

	 @Autowired
	 private IInStockInfoService inStockInfoService;
	 /**
	  * 分页查询入库记录
	  * @param page
	  * @param rows
	  * @return
	  */
	 @RequestMapping(value="/href/inStockInfoList")
	 @ResponseBody
	 public DataGrid getInStockInfoList(String page, String rows,String inStockDate){
			int page1 = Integer.parseInt(page);
			int rows1 = Integer.parseInt(rows);
			List<InStockInfo> list = new ArrayList<>();
			int total = 0;
			if(inStockDate==null||inStockDate==""){
			list = inStockInfoService.getInStockInfoList((page1-1)*rows1,rows1);
			total = inStockInfoService.getCount();
			dataGrid.setRows(list);
			dataGrid.setTotal(total);
			}else{
				list = inStockInfoService.getInStockInfoListBydate(inStockDate,(page1-1)*rows1,rows1);
				total = inStockInfoService.getCount1(inStockDate);
				dataGrid.setRows(list);
				dataGrid.setTotal(total);
			}
			return dataGrid;
	 }
	 /**
	  * 添加入库记录
	  * @param inStockInfo
	  * @return
	  */
	 @ResponseBody
	 @RequestMapping("/href/addInStockInfo")
	 public int addInStockInfo(InStockInfo inStockInfo){
		 
		 int i = inStockInfoService.addInStockInfo(inStockInfo);
		 return i;
	 }
	 /**
	  * 查询入库记录
	  * @param materielName
	  * @return
	  */
	 @ResponseBody
	 @RequestMapping(value="/href/SearchInstockinfo")
	 public InStockInfo SearchInstockinfo(String materielName){
		 
		 InStockInfo inStockInfo = inStockInfoService.getInStockInfo(materielName);
		 
		 return inStockInfo;
	 }
	 
}
